#include <stdio.h>
#include <stdlib.h>

typedef int ElemType;

typedef struct Node
{
    ElemType data;
    struct Node *next;
}Node;

Node *InitList()
{
    Node *head = (Node *)malloc(sizeof(Node));
    head->data = 0;
    head->next = NULL;
    return head;
}

int InsertHead(Node* L , ElemType e)
{
    Node *p = (Node*)malloc(sizeof(Node));  //创建新节点
    p->data = e;    
    p->next = L->next;  //新节点指向头节点的下一个节点
    L->next = p;    //头节点指向新节点
    return 1;
}

void listNode(Node *L)
{
    Node *p = L->next;
    while(p != NULL)
    {
        printf("%d\n",p->data);
        p = p->next;
    }
    printf("\n");
}

Node* InsertTail(Node *L , ElemType e)
{
    Node *p = L;
    while(p->next != NULL)  //找到尾节点
    {
        p = p->next;
    }
    Node *q = (Node *)malloc(sizeof(Node));
    q->data = e;
    p->next = q;    //尾节点指向新节点
    q->next = NULL;  
    return q;
}

int InsertNode(Node *L , int pos , ElemType e)
{
    Node *p = L;
    int i = 0;
    while(i < pos - 1)  //找到要插入位置的前一个节点
    {
        p = p->next;
        i++;
        if(p == NULL)
        {
            return 0;
        }
    }

    Node *q = (Node *)malloc(sizeof(Node));
    q->data = e;    //新节点数据域赋值
    q->next = p->next;  //新节点指向前一个节点的下一个节点
    p->next = q;    //前一个节点指向新节点
    return 1;
}

int DeleteNode(Node *L , int pos)
{
    Node *p = L;
    int i = 0;
    while(i < pos - 1)  //找到要删除位置的前一个节点
    {
        p = p->next;
        i++;
        if(p == NULL)
        {
            return 0;
        }
    }
    if(p->next == NULL)
    {
        return 0;
    }
    Node *q = p->next;  //要删除的节点
    p->next = q->next;  //前一个节点指向要删除节点的下一个节点
    free(q);
    return 1;
}

int main()
{

}